package com.example.news.Acg;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.news.R;
import com.squareup.picasso.Picasso;

import java.util.List;
import java.util.Random;

public class AcgAdapter extends RecyclerView.Adapter<AcgAdapter.ViewHolder> {
    private Context context;
    private List<AcgUrl> list;
    public AcgAdapter(Context context,List<AcgUrl> list){
        this.list = list;
        this.context = context;
    }
    @NonNull
    @Override
    public AcgAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_acg,parent,false);
        return new AcgAdapter.ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull AcgAdapter.ViewHolder holder, int position) {

//        ViewGroup.LayoutParams params = holder.acgPic.getLayoutParams();
//        params.height = params.height + new Random().nextInt(100);
//        holder.acgPic.setLayoutParams(params);


        Glide.with(context).load(list.get(position).getImageUrl()).into(holder.acgPic);

    }

    @Override
    public int getItemCount() {
        if(list != null){
            return list.size();
        }else {
            return 0;
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView acgPic;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            acgPic = itemView.findViewById(R.id.acgPic);
        }
    }
}
